﻿/******************************************************************************
 * 
 * Announce: CSharpKit, Basic algorithms, components and definitions.
 *           Copyright (C) ShenYongchen.
 *           All rights reserved.
 *   Author: 申永辰.郑州 (shenyczz@163.com)
 *  WebSite: http://github.com/shenyczz/CSharpKit
 *
 * THIS CODE IS LICENSED UNDER THE MIT LICENSE (MIT).
 * THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF 
 * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
 * IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
 * PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
 * 
******************************************************************************/

using System;
using CSharpKit.Numerics.Distributions;

namespace CSharpKit.Numerics.LinearAlgebra
{
    /// <summary>
    /// 矩阵工厂
    /// </summary>
    public static class MatrixFactory
    {
        /// <summary>
        /// MatrixStorageDense ColumnMajor <br/>
        /// MatrixStorageSparse CompressedRow <br/>
        /// MatrixStorageDiagonal <br/>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="storage"></param>
        /// <returns></returns>
        public static Matrix<T> OfStorage<T>(MatrixStorage<T> storage)
            where T : struct, IFormattable, IEquatable<T>
        {
            return Matrix<T>.Builder.OfStorage(storage);
        }

        public static Matrix<T> SameAs<T, TU>(Matrix<TU> example)
            where T : struct, IFormattable, IEquatable<T>
            where TU : struct, IFormattable, IEquatable<TU>
        {
            return Matrix<T>.Builder.SameAs(example);
        }


        // shenyc

        #region Dense

        /// <summary>
        /// 构造密集矩阵（默认列主序）
        /// </summary>
        /// <param name="rows">行数</param>
        /// <param name="columns">列数</param>
        /// <typeparam name="T">矩阵类型</typeparam>
        /// <returns></returns>
        public static Matrix<T> Dense<T>(int rows, int columns)
            where T : struct, IFormattable, IEquatable<T>
        {
            return Matrix<T>.Builder.Dense(rows, columns);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="rows"></param>
        /// <param name="columns"></param>
        /// <param name="tvalue">矩阵元素的默认值</param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static Matrix<T> Dense<T>(int rows, int columns, T tvalue)
            where T : struct, IEquatable<T>, IFormattable
        {
            return Matrix<T>.Builder.Dense(rows, columns, tvalue);
        }

        #endregion



        public static Matrix<T> Random<T>(int rows, int columns)
            where T : struct, IEquatable<T>, IFormattable
        {
            return Matrix<T>.Builder.Random(rows, columns);
        }

        public static Matrix<T> Random<T>(int rows, int columns, IContinuousDistribution distribution)
            where T : struct, IEquatable<T>, IFormattable
        {
            return Matrix<T>.Builder.Random(rows, columns, distribution);
        }





        //}}@@@
    }


}

